<template>
  <div class="bbgl_box">
    <header-comm></header-comm>
    <div class="header_sele" :style="$parent.$parent.collapsed==false?'left: 10%':'left:80px'">
      <div></div>
      <div class="add_qy">
        <a-input placeholder="请输入要查询的关键字" v-model="searval" @change="search" />
      </div>
    </div>
    <div class="bcg">
      <div class="bbgl">
        <a-table :columns="columns" @change="getywpxList" :dataSource="data" :pagination="true">
          <template slot="examine" slot-scope="text, record, index">
            <div class>
              <a-tag v-if="text==0" color="#87d068">未审核</a-tag>
              <a-tag v-if="text==1" color="#2db7f5">通过</a-tag>
              <a-tag v-if="text==2" color="#f50">审核未通过</a-tag>
            </div>
          </template>
          <template slot="operation" slot-scope="text, record, index">
            <div class="editable-row-operations">
              <a class="del" @click="shenghe(record.id_num,1)">申请通过</a>
              <a class="del" @click="shenghe(record.id_num,2)">申请不通过</a>
              <a class="del" @click="ywpxdel(record)">删除</a>
              <!-- <a class="del" @click="khbbExamine(1,record)">审核通过</a> -->
              <!-- <a class="del" @click="khbbExamine(2,record)">审核不通过</a> -->
            </div>
          </template>
        </a-table>
        <div class="shyy_tk" v-if="shyyflag">
          <div class="sryy">
            <div class="close" @click="close">
              <a-icon type="close" />
            </div>
            <div>
              <a-textarea
                v-if="shyyval.key==1"
                :maxlength="10"
                v-model="remark"
                placeholder="请输入金额"
                :rows="4"
              />
              <a-textarea
                v-if="shyyval.key==2"
                v-model="remark"
                placeholder="请输入审核不通过原因"
                :rows="4"
              />
            </div>
            <div class="btn">
              <a-button type="primary" @click="subkhbbExamine">提交</a-button>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import qs from "qs";
import headerComm from "../header-comm/header.vue";
const columns = [
  {
    title: "姓名",
    dataIndex: "name"
  },
  {
    title: "联系方式",
    dataIndex: "lxfs"
  },
  {
    title: "参加人数",
    dataIndex: "count"
  },
  {
    title: "培训标题",
    dataIndex: "trains_title"
  },
  {
    title: "备注",
    dataIndex: "bz"
  },
  {
    title: "审核状态",
    dataIndex: "examine",
    scopedSlots: { customRender: "examine" }
  },
  {
    title: "审核原因",
    dataIndex: "remark",
    scopedSlots: { customRender: "remark" }
  },
  {
    title: "价格",
    dataIndex: "payPrice"
  },
  {
    title: "操作",
    dataIndex: "operation",
    scopedSlots: { customRender: "operation" }
  }
];
const data = [];
export default {
  data() {
    return {
      data,
      columns,
      pagination: {
        defaultPageSize: 10,
        showTotal: total => `共 ${total} 条数据`,
        total: 0,
        current: 1
      },
      shyyflag: false,
      remark: "",
      shyyval: {
        key: "",
        val: ""
      },
      searval: ""
    };
  },

  methods: {
    getywpxList(pagination) {
      this.pagination.current = pagination.current;
      this.axios
        .post(
          "fhl/ywpx/ywpxList.php",
          qs.stringify({
            page: this.pagination.current,
            pageSize: pagination.defaultPageSize,
            filed: this.searval
          })
        )
        .then(res => {
          console.log(res);
          if (res.data.code == 303) {
            this.pagination.total = res.data.total;
            for (var i = 0; i < res.data.result.data.length; i++) {
              res.data.result.data[i].key = i;
            }
            this.data = res.data.result.data;
          } else {
            this.data = [];
          }
        });
    },

    search() {
      this.getywpxList(this.pagination);
    },
    shenghe(id_num, examine_type) {
      this.shyyflag = true;
      this.shyyval.key = examine_type;
      this.shyyval.val = id_num;
    },
    subkhbbExamine() {
      if (this.shyyval.key == 2) {
        if (this.remark.trim()) {
          this.Examine();
        } else {
          this.$notification["error"]({
            message: "失败",
            description: "请输入审核不通过原因！"
          });
        }
      } else {
        if (this.remark.trim()) {
          this.Examine();
        } else {
          this.$notification["error"]({
            message: "失败",
            description: "请输入金额！"
          });
        }
      }
    },
    Examine() {
      this.axios
        .post(
          "fhl/ywpx/ywpxExamine.php",
          qs.stringify({
            id_num: this.shyyval.val,
            examine_type: this.shyyval.key,
            payPrice: this.shyyval.key == 1 ? this.remark : "",
            remark: this.shyyval.key == 2 ? this.remark : ""
          })
        )
        .then(res => {
          console.log(res);
          if (res.data.code == 303) {
            this.getywpxList(this.pagination);
            this.close();

            if (res.data.sendMsg == "success") {
              this.$notification["success"]({
                message: "成功",
                description: res.data.msg + "，短信发送成功"
              });
            } else {
              this.$notification["error"]({
                message: "失败",
                description: res.data.msg + "，短信发送失败"
              });
            }
          } else {
            this.getywpxList(this.pagination);
            this.$notification["error"]({
              message: "失败",
              description: res.data.msg
            });
          }
        });
    },
    close() {
      this.shyyflag = false;
      this.remark = "";
    },
    ywpxdel(value) {
      this.axios
        .post(
          "fhl/ywpx/ywpxDelete.php",
          qs.stringify({
            id_num: value.id_num
          })
        )
        .then(res => {
          console.log(res);
          if (res.data.code == 303) {
            this.getywpxList(this.pagination);
            this.$notification["success"]({
              message: "成功",
              description: res.data.msg
            });
          } else {
            this.$notification["error"]({
              message: "失败",
              description: res.data.msg
            });
          }
        });
    }
  },
  components: {
    headerComm
  },

  created() {
    this.getywpxList(this.pagination);
  }
};
</script>

<style lang='less'>
.header_sele {
  position: fixed;
  top: 55px;
  left: 200px;
  z-index: 999;
  text-align: right;
  width: 90%;
  background-color: #fff;
  box-shadow: 5px 5px 5px #ccc;
  // height: 50px;
  padding: 10px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.bbgl {
  position: relative;
  top: 143px;
  left: 1%;
  background: #fff;
  width: 98%;
}
.shyy_tk {
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.5);
  width: 100%;
  height: 1000px;
  z-index: 999;
  .sryy {
    position: absolute;
    left: 35%;
    top: 10%;
    width: 30%;
    background: #fff;
    height: 246px;
    text-align: center;
    padding: 46px;
    textarea {
      width: 96%;
    }
    .btn {
      margin-top: 20px;
      text-align: center;
    }
  }
}
</style>
